<html>
<head>
<script>
//<![CDATA[
function decodePassword(pass, key)
{
	var result = "";
	var n1, n2;

	if(key.length == 0)
		return pass;

	for(n1 = 0, n2 = 0; n1 < pass.length; n1 += 4) {
		if(n1 + 4 > pass.length)
			break;
		result += String.fromCharCode( Number("0x"+pass.substr(n1, 4)) ^ key.charCodeAt(n2++) );
		if(n2 >= key.length)
			n2 = 0;
	}
	return result;
}

function escapeHtml(html) {
	return html.split("&").join("&amp;").split( "<").join("&lt;").split(">").join("&gt;");
}

function tryDecode() {
	var pass
	try {
		pass = decodePassword(document.getElementById("encoded").value, document.getElementById("jid").value);
	} catch (e) {
		pass = "Encode failed: " + e
	}
	document.getElementById("result").innerHTML = escapeHtml(pass);
}

//]]>
</script>
</head>
<body>
	<h2>Password recovery utility</h2>
	Enter your jid and your encoded password from accounts.xml and press "decode"
<table>
<tr><td>JID: </td><td><input id='jid' /></td></tr>
<tr><td>Encoded password: </td><td><input id='encoded' /></td></tr>
<tr><td>Result: </td><td id='result'></td></tr>
<tr><td colspan='2' style='text-align:right'><input type='button' value="decode" onclick="tryDecode()" /></td></tr>
</table>

</body>
</html>
